import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView,
    },
    {
      path: '/show',
      name: 'show',
      component: () => import('../views/Show.vue')
    },
    {
      path: '/spotsAdmin',
      name: 'spotsAdmin',
      component: () => import('../components/adminView/SpotsAdmin.vue')
    },
    {
      path: '/map',
      name: 'map',
      component: () => import('../components/Driver/MapDriver.vue')
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/LoginView.vue')
    },
    {
      path: '/weather',
      name: 'weather',
      component: () => import('../views/Weather.vue')
    },
    // {
    //   path: '/about',
    //   name: 'about',
    //   // route level code-splitting
    //   // this generates a separate chunk (About.[hash].js) for this route
    //   // which is lazy-loaded when the route is visited.
    //   component: () => import('../views/AboutView.vue'),
    // },
  ],
})
router.beforeEach(async (to, from) => {
  if (!localStorage.getItem('user') && to.path !== '/login') {
    // 将用户重定向到登录页面
    return { name: 'login' }
  }
})
export default router
